package de.wittekind.bundesjugendspiele.server;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Sascha Wegener
 * 
 * @version 17.04.2013
 */
public class DatabaseConnectionManager {

	protected static Connection connection;


	public static Connection getConnection() {
		return connection;
	}

	public static void close() {
		try {
			if (connection != null && !connection.isClosed())
				connection.close();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}

	public static void clearTables() {
		try {
			Connection c = getConnection();
			Statement s = c.createStatement();
			s.executeUpdate("delete from riege");
			s.executeUpdate("delete from schueler");
			s.executeUpdate("delete from versuch");
			s.close();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}

	public static void shutdown() {
		try {
			Connection c = getConnection();
			Statement s = c.createStatement();
			s.execute("shutdown");
			s.close();
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
	}

}
